$(function () {
    $("#form")[0].reset();
    Time();
})
function Time() {
    var time = new Date();
    var y = time.getFullYear();
    var mon = time.getMonth() + 1; //0-11
    var d = time.getDate();
    var h = time.getHours();
    var m = time.getMinutes();
    var s = time.getSeconds();
    $("#datetime").val(y + "-" + mon + "-" + d + " " + h + ":" + m + ":" + s);
    let u = localStorage.getItem("user");
    let user = JSON.parse(u);
    $("#name").val(user.rname);
}


function jj() {
    $.ajax({
        type: "post",
        url: "/Dflile.do/chaname",
        data: {name: $("[name='productname']").val()},
        success: function (data) {
            if (data != 0) {
                alert("名字重复了，无法添加！")
            } else {
                $("#delModal").modal("show");
                let productname = $("[name='productname']").val()
                let shic = $("[name='listprice']").val()
                let jih = $("[name='costprice']").val()
                $("#tishi").text(null)

                if (productname == "" || productname == null) {
                    $("#tishi").text("产品名称不能为空！")
                    $("#delModal").modal("show");
                } else if (shic == "" || shic == null) {
                    $("#tishi").text("市场价不能为空！")
                    $("#delModal").modal("show");
                } else if (jih == "" || jih == null) {
                    $("#tishi").text("成本价不能为空！")
                    $("#delModal").modal("show");
                } else if (parseInt(shic) > parseInt(jih)) {
                    $("#tishi").text("提交成功！")
                    $("#tishi").css("color", "lime")
                    $("#delModal").modal("show");
                    $("#form").submit();
                } else {
                    $("#tishi").text("成本价不能高于市场价！")
                    $("#delModal").modal("show");
                }
            }
        }
    })
}